-- type_spell_bonus
-- create by shuzy
-- 道具： 随机指定系的卷轴奖励
-- 参数列说明：(type, count) type系别（配置0时是随机系别）；count数量

return {
    apply = function(source, target, classId, value)
        local range = string.explode(value[2], "~");
        local min, max;

        if #range > 1 then
            min = tonumber(range[1]);
            max = tonumber(range[2]);
        else
            min = tonumber(range[1]);
            max = min;
        end

        assert(max >= min);

        -- 奖励的卷轴数量
        local differ = max - min;
        local rand = DungeonM.getRandSeed("type_spell_bonus");
        local count = min + rand % (differ + 1);

        -- 奖励卷轴
        local arr = { FIRE, WATER, THUNDER, LIGHTER, DARK, EARTH };
        local spellType, spell;
        for i = 1, count do
            if value[1] == 0 then
                spellType = arr[DungeonM.getRandSeed("type_spell_bonus") % #arr + 1];
            else
                spellType = value[1];
            end

            spell = SpellM.fetchSpell(spellType, DungeonM.getRandSeed("type_spell_bonus"));
            BonusM.doBonus({ 1, spell, 1, }, "property_type_spell_bonus");
        end
    end,
};
